package com.example.mobile2032021606168xmy0412homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private TextView tvMainTarget;
    private TextView tvMainRequire;
    private TextView tvMainNum1;
    private TextView tvMainNum2;
    private EditText edtMainNum1;
    private EditText edtMainNum2;
    private Button btnMainResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMainResult.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String inputText1=edtMainNum1.getText().toString();
                String inputText2=edtMainNum2.getText().toString();
                int num1=Integer.valueOf(inputText1).intValue();
                int num2=Integer.valueOf(inputText2).intValue();
                num1=num1+num2;
                inputText1=String.valueOf(num1);
                tvMainNum1.setText(inputText1);
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        tvMainTarget = (TextView) findViewById(R.id.tv_main_target);
        tvMainRequire = (TextView) findViewById(R.id.tv_main_require);
        tvMainNum1 = (TextView) findViewById(R.id.tv_main_num1);
        tvMainNum2 = (TextView) findViewById(R.id.tv_main_num2);
        edtMainNum1 = (EditText) findViewById(R.id.edt_main_num1);
        edtMainNum2 = (EditText) findViewById(R.id.edt_main_num2);
        btnMainResult = (Button) findViewById(R.id.btn_main_result);
    }
}